package com.wrox.beginspring.pix.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Date;

public class Album implements Serializable {

    private Integer id;
    private PixUser user;
    private String name;
    private String description;
    private Date creationDate = new Date();
    private String[] labels;
    private List<Picture> pictures = new ArrayList<Picture>();

    public void setId(Integer id) {
        this.id = id;
    }

    public void setUser(PixUser user) {
        this.user = user;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public void setLabels(String[] labels) {
        this.labels = labels;
    }

    public void setPictures(List<Picture> pictures) {
        this.pictures = pictures;
    }

    public Album() {
    }

    public Integer getId() {
        return id;
    }

    public PixUser getUser() {
        return user;
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public String[] getLabels() {
        return labels;
    }

    public List<Picture> getPictures() {
        return pictures;
    }

    public Album(String name) {
        this.name = name;
    }

    public void addNewPicture(Picture picture) {
        picture.setAlbum(this);
        pictures.add(picture);
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 79 * hash + (this.user != null ? this.user.hashCode() : 0);
        hash = 79 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 79 * hash + (this.description != null ? this.description.hashCode() : 0);
        hash = 79 * hash + (this.creationDate != null ? this.creationDate.hashCode() : 0);
        hash = 79 * hash + Arrays.deepHashCode(this.labels);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Album other = (Album) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.user != other.user && (this.user == null || !this.user.equals(other.user))) {
            return false;
        }
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if ((this.description == null) ? (other.description != null) : !this.description.equals(other.description)) {
            return false;
        }
        if (this.creationDate != other.creationDate && (this.creationDate == null || !this.creationDate.equals(other.creationDate))) {
            return false;
        }
        if (!Arrays.deepEquals(this.labels, other.labels)) {
            return false;
        }
        return true;
    }
}